#!/bin/bash

# 定义关键变量
DB_USER="AML"
DB_PASSWORD="123456" # 生产环境建议改用 --password-file
TABLES=('AML_ACCOUNT_MASTER'
 'AML_ALERT' 
 'AML_CUSTOMER_MASTER' 
 'AML_MONITORING_RULE' 
 'AML_SCREENING_RESULT'
 'AML_SUSPICIOUS_TXN_REPORT'  
 'AML_TRANSACTION_DETAIL'
 'AML_UBO_INFO'
 'AML_WATCHLIST_DETAIL' 
 'AML_WATCHLIST_MASTER')      # 待导入的10张表名列表
HIVE_DB="zyt" # Hive 目标数据库
LOG_FILE="/log/zyt.log"
DT=$(date +%Y%m%d)

mkdir -p $(dirname $LOG_FILE)

for table in "${TABLES[@]}"
do

    hive_table="ODS_${table}" 

    echo "[$(date +'%F %T')] 开始导入表: $table → Hive表: $hive_table" >> $LOG_FILE

    sqoop import \
        --connect jdbc:oracle:thin:@192.168.242.1:1521:orcl \
        --username $DB_USER \
        --password $DB_PASSWORD \
        --table "$table" \
        --hcatalog-database $HIVE_DB \
        --hcatalog-table "$hive_table" \
        --hive-partition-key etl_date \
        --hive-partition-value "$DT" \
        -m 1 \
        >> $LOG_FILE 2>&1

    if [ $? -eq 0 ]; then
        echo "[$(date +'%F %T')] 表 $table 导入成功" >> $LOG_FILE
    else
        echo "[$(date +'%F %T')]  表 $table 导入失败！" >> $LOG_FILE
        exit 1
    fi
done